<?php

#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
include_once ("include/class.time.php5");
include_once ("include/bday.php5");
$svo = new db("svoptik");
$tools = new tool();
$time = new TimeUtil();

include_once ("include/global_fix_extern.inc");

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik.tpl",
	"navi" => "navi.tpl",
	"ticker" => "ticker.tpl",
	"news" => "news.tpl"
));
#--------------------------------------------------
$t->set_var(array (
	"FORWARD" => ""
));

#--------------------------------------------------
# CREATE NAVIGATION RIGHT
#--------------------------------------------------
$links = "";
$prev_year = "";
$m = 0;
$get_data = $svo->doSQL("select distinct date from report order by date desc;");
while ($row = $svo->getRecordset($get_data)) {
	if (substr($row['date'], 0, 4) != $prev_year) {
		$get_year[$m] = substr($row['date'], 0, 4);
		$m++;
	}
	$prev_year = substr($row['date'], 0, 4);
}
for ($y = 0; $y < count($get_year); $y++)
	$url[$y] = array (
		"URL" => "archive.php5?year=" . $get_year[$y] . "",
		"URL-TEXT" => "Archiv " . $get_year[$y],
		"ONCLICK" => "",
		"TARGET" => "_self"
	);

for ($i = 0; $i < count($url); $i++) {
	$links .= "
	        <tr height=\"15\">
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
				<td valign=\"top\"><a href=\"" . $url[$i]['URL'] . "\" class=\"sitenav\" target=\"" . $url[$i]['TARGET'] . "\" onClick=\"" . $url[$i]['ONCLICK'] . "\">" . $url[$i]['URL-TEXT'] . "</a></td>
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
			<tr height=\"15\">
	            <td colspan=\"3\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
	       ";
}
$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "ARCHIVE"
#--------------------------------------------------

if (empty ($year))
	$year = date("Y");
$content = "";
$sql = $svo->doSQL("select * from " . $table['Berichte'] . " where date like '" . $year . "%' order by date desc;");
$i = 0;

while ($tupel = mysql_fetch_array($sql)) {
	if (strlen($tupel['text']) > 250)
		$link = "... <a href=\"show_areport.php5?id=" . $tupel['report_id'] . "\" class=\"news\">mehr</a>";
	else
		$link = "&nbsp";
	$auth = $svo->readRecordset("select * from " . $table['User'] . " where usr_id='" . $tupel['author_id'] . "';");
	$author = "<a href=\"mailto:" . $auth['usr_email'] . "\" class=\"news\">" . $auth['usr_vname'] . " " . $auth['usr_name'] . "</a>";
	if ($bdayTrue && $i == 0) {
		$ausgabe = "<tr><td valign='top' align='center' class='bday'>" . $gruss . "</td></tr>";
		$i++;
	} else {
		$ausgabe = "";
	}

	$t->set_var(array (
		"LINK" => $link,
		"KATEGORIE" => $tools->html_replace($tupel['cat']
	) . " " . $tools->html_replace($tupel['team']), "HEADLINE" => $tools->html_replace($tupel['headline']), "DATUM" => $time->out($tupel['date'], 'd'), "TEXT" => substr($tools->html_replace($tupel['text']), 0, 250), "AUTHOR" => $author, "BDAY" => $ausgabe, "ANCHOR" => $tupel['report_id']));
	$content .= $t->parse("", "news", true);
}
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => "NEWS -> ARCHIV " . $year,
	"ticker" => $ticker,
	"content" => $content . "<br>",
	"navi" => $right_nav,
	"SYNCHRONIZE" => " "
));

$t->parse("ALL", "page", true);
$t->p("ALL");
?>
